package com.tj.collection.controller.lending;

import com.alibaba.fastjson.JSONObject;
import com.tj.collection.bean.ApiResponse;
import com.tj.collection.controller.lending.response.ClEmergencyContactInfoResponse;
import com.tj.collection.controller.lending.response.ClUserBaseInfoResponse;
import com.tj.collection.db.dao.ClReceiverDao;
import com.tj.collection.db.dao.ClReceiverDetailDao;
import com.tj.collection.db.entity.ClReceiverDetailEntity;
import com.tj.collection.db.entity.ClReceiverEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author: Karl
 * Date: 2020/12/22 4:20 下午
 */
@RestController
@RequestMapping("/collection/v2")
public class ClUserController {

    @Autowired
    private ClReceiverDao clReceiverDao;

    @Autowired
    private ClReceiverDetailDao clReceiverDetailDao;

    /**
     * 查询用户基础信息
     *
     * @param jsonObject
     * @return
     */
    @RequestMapping("/user/base/info")
    public ApiResponse<ClUserBaseInfoResponse> clUserBaseInfo(@RequestBody JSONObject jsonObject) {
        String tradeNo = jsonObject.getString("tradeNo");
        ClReceiverEntity clReceiverEntity = clReceiverDao.selectLastByOrderNo(tradeNo);
        ClReceiverDetailEntity clReceiverDetailEntity = clReceiverDetailDao.selectOneByCollectionNo(clReceiverEntity.getCollectionNo());
        ClUserBaseInfoResponse baseInfoVO = new ClUserBaseInfoResponse(clReceiverDetailEntity);
        return new ApiResponse<>(baseInfoVO);
    }

    /**
     * 紧急联系人(基础信息)
     *
     * @return
     */
    @RequestMapping(value = "/user/emergency/contacts/list")
    public ApiResponse<ClEmergencyContactInfoResponse> profileContactsGet(@RequestBody JSONObject jsonObject) {
        String tradeNo = jsonObject.getString("tradeNo");

        ClReceiverEntity clReceiverEntity = clReceiverDao.selectLastByOrderNo(tradeNo);
        ClReceiverDetailEntity clReceiverDetailEntity = clReceiverDetailDao.selectOneByCollectionNo(clReceiverEntity.getCollectionNo());

        ClEmergencyContactInfoResponse contactsInfoVO = new ClEmergencyContactInfoResponse(clReceiverDetailEntity);
        return new ApiResponse<>(contactsInfoVO);
    }
}
